package com.woniuxy.conf;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


import java.util.HashMap;
import java.util.Map;


/**
 * @Author: 曾令忠
 * @Description: 延时队列插件
 * @Date: 2020/7/7 0007-下午 2:33
 */
@Configuration
public class RabbitConf3 {
    @Bean
    public Queue delayPluginQueue(){
        return new Queue("delayPluginQueue");
    }
    @Bean
    public CustomExchange customExchange(){
        Map<String,Object> map = new HashMap<>();
        //指定交换机的类型
        map.put("x-delayed-type","direct");
        return new CustomExchange("customExchange","x-delayed-message",true,false,map);

    }

    @Bean
    public Binding bindingCustomExchangeAndQueue(CustomExchange customExchange, Queue delayPluginQueue){
        return BindingBuilder.bind(delayPluginQueue).to(customExchange).with("dalay_key").noargs();
    }

}
